$(document).ready(function(){
	getdepartment(pId);
	gettitle(pId);
	getlist(pId);
});	
function getdepartment(pId){
	$.ajax({  
		url: "../mobile_pingjia/get_department"
		,type:'post'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"pId":pId}) 
		,dataType:'json'
		,success: function(res){
			console.log(res);
			if(pId=='131' || pId =='135' || res.data[0].path.indexOf('131/') > -1){
				$('#title').append('<div class="w80p align_center blue">今度烘焙</div>')
			}else{
				$('#title').append('<div class="w80p align_center blue">金虎便利</div>')
			}
			if(res.data[0].state == 1){}else{
				$('#department').append('<div class="w94 add_pad_lr3 h60p bg_white fle_content_row fle_just_btw fle_alig_center">'
					+'<div class="w40p h40p add_rad_8p bg_blue white add_mar_r2 fs_13p align_center add_weight">'+res.data[0].name.substring(0,2)+'</div>'
					+'<div class="fle_gro_1 w0 fs_14p blue" onclick = "pingjia(\''+res.data[0].groupId+'\',\''+res.data[0].name+'\',1)">'+res.data[0].name+'</div></div>'
				);
			}
		}
	});
}
function getlist(pId){
	$.ajax({  
		url: "../../unite_platform/mobile_pingjia/get_next"
		,type:'post'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"pId":pId}) 
		,dataType:'json'
		,success: function(res){
			console.log(res);
			for(var i =0;i<res.data.length;i++){
				$('#listid').append(
					'<div class="w94 add_pad_lr3 h60p add_bor_b_gray fle_content_row fle_just_btw fle_alig_center">'
					+'<div class="fle_gro_1 w0 fle_content_col fle_just_eve fle_alig_center" onclick = "pingjia(\''+res.data[i].groupId+'\',\''+res.data[i].name+'\',1)">'
					+'<div class="w100 h20p fs_15p gray" style="color:black!important">'+res.data[i].name+'</div>'
					+'</div>'
					+'<div class="fle_gro_1 align_right" onclick="next(\''+res.data[i].groupId+'\')">'
					+'<i class="iconfont gray">&#xe611;</i>'	
					+'</div>'
					+'</div>'
				)
			}
		}
	});
	$.ajax({  
		url: "../../unite_platform/mobile_pingjia/get_user"
		,type:'post'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"pId":pId}) 
		,dataType:'json'
		,success: function(res){
			var photohtml="";
			for(var i =0;i<res.data.length;i++){
				if(res.data[i].photo=='' || res.data[i].photo==undefined){
						photohtml='<div class="w40p h40p add_rad_8p bg_blue white add_mar_r2 fs_13p align_center add_weight">'+res.data[i].name.substring(res.data[i].name.length-2,res.data[i].name.length)+'</div>';
					}else{
						photohtml='<div class="w40p h40p add_rad_8p white add_mar_r2 fs_13p align_center add_weight"><img class="w100 add_rad_8p w40p h40p" src="'+res.data[i].photo+'" /></div>'
					}
				$('#listid').append(
					'<div class="w94 add_pad_lr3 h60p add_bor_b_gray fle_content_row fle_just_btw fle_alig_center" onclick = "pingjia(\''+res.data[i].userId+'\',\''+res.data[i].name+'\',0)">'
				  // +'<div class="w40p h40p add_rad_8p bg_blue white add_mar_r2 fs_13p align_center add_weight">'+res.data[i].name.substring(res.data[i].name.length-2,res.data[i].name.length)+'</div>'
				   +photohtml
				   +'<div class="fle_gro_1 w0 fle_content_col fle_just_eve fle_alig_center">'
				   +'<div class="w100 h20p fle_content_row fle_just_start fle_alig_center">'
				   +'<div class="w50p fs_14p">'+res.data[i].name+'</div>'
				   +'</div>'
				//   +'<div class="w100 h20p fs_13p gray"></div>'
				   +'</div></div>'
				)
			}
		}
	});
}
function next(groupId){
	 var  url = "pingjia_check?pId="+groupId;//此处拼接内容
	 window.location.href = url;
}
function pingjia(userId,username,type){
	 var  url = "pingjia_woyaopj?userId="+userId+'&username='+encodeURI(encodeURI(username))+'&type='+type;//此处拼接内容
	 window.location.href = url;
}
function gettitle(pId){
	$.ajax({  
		url: "../../unite_platform/mobile_pingjia/get_title"
		,type:'post'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"pId":pId}) 
		,dataType:'json'
		,success: function(res){
			console.log(res);
			for(var i =1;i<res.data.length;i++){
				$('#title').append(
					'<i class="iconfont gray">&#xe611;</i>'
					+'<div class="w80p align_center blue">'+res.data[i].name+'</div>'
				)
			}
		}
	});
}
$("#searchtext").on("input",function(){
	$('#listid').html("");
	if($("#searchtext").val() == ""){
		getlist(pId);
	}else{
		$.ajax({  
			url: "../../unite_platform/mobile_pingjia/get_search_user"
			,type:'post'
			,async: false
			,contentType: "application/json; charset=utf-8"
			,data:JSON.stringify({"name":$("#searchtext").val()}) 
			,dataType:'json'
			,success: function(res){
				console.log(res);
				var photohtml="";
				for(var i =0;i<res.data.length;i++){
					if(res.data[i].photo=='' || res.data[i].photo==undefined){
						photohtml='<div class="w40p h40p add_rad_8p bg_blue white add_mar_r2 fs_13p align_center add_weight">'+res.data[i].name.substring(res.data[i].name.length-2,res.data[i].name.length)+'</div>';
					}else{
						photohtml='<div class="w40p h40p add_rad_8p white add_mar_r2 fs_13p align_center add_weight"><img class="w100 add_rad_8p w40p h40p" src="'+res.data[i].photo+'" /></div>'
					}
					$('#listid').append(
						'<div class="w94 add_pad_lr3 h60p add_bor_b_gray fle_content_row fle_just_btw fle_alig_center" onclick = "pingjia(\''+res.data[i].userId+'\',\''+res.data[i].name+'\',0)">'
					 //  +'<div class="w40p h40p add_rad_8p bg_blue white add_mar_r2 fs_13p align_center add_weight">'+res.data[i].name.substring(res.data[i].name.length-2,res.data[i].name.length)+'</div>'
					   +photohtml
					   +'<div class="fle_gro_1 w0 fle_content_col fle_just_eve fle_alig_center">'
					   +'<div class="w100 h20p fle_content_row fle_just_start fle_alig_center">'
					   +'<div class="w50p fs_14p">'+res.data[i].name+'</div>'
					   +'</div>'
					   //+'<div class="w100 h20p fs_13p gray"></div>'
					   +'</div></div>'
					)
				}
			}
		});
	}
})
function pingjia(userId,username,type){
	 var  url = "pingjia_woyaopj?userId="+userId+'&username='+encodeURI(encodeURI(username))+'&type='+type;//此处拼接内容
	 window.location.href = url;
}